﻿<%@ WebHandler Language="C#" Class="hGroup" %>
using System;
using System.Web;
using System.Data;
using System.Collections.Generic;
using BLL.System;
using CommonLib; 
using System.Web.SessionState;
using Entities.System; 

public class hGroup : IHttpHandler, IRequiresSessionState
{

    public void ProcessRequest (HttpContext context) {
        handle(context);
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }
    private void handle(HttpContext context)
    {
        string action = context.Request.QueryString["action"];
        string result = string.Empty;
        int? pageSize = null;
        if (!string.IsNullOrEmpty(context.Request["rows"])) pageSize = Convert.ToInt32(context.Request["rows"]);
        int? pageNum = null;
        if (!string.IsNullOrEmpty(context.Request["rows"])) pageNum = Convert.ToInt32(context.Request["page"]);
        Dictionary<string, string> dicLike = new Dictionary<string, string>();
        Dictionary<string, string> dicEqual = new Dictionary<string, string>();
        try
        {
            if (context.Session["user"] == null) throw new Exception("登录超时！");
            User user = context.Session["user"] as Entities.System.User;
            GroupBO bo = new GroupBO();
            switch (action )
            {
                
                case "get":
                    //群组
                    dicLike.Add("GROUP_NAME", context.Request["sGROUPNAME"]);
                    if (!string.IsNullOrEmpty(context.Request["q"])) 
                        dicLike["GROUP_NAME"] = context.Request["q"];
                    dicLike.Add("GROUP_ID", context.Request["sGROUPID"]);
                    //超级管理员
                    if (user.USER_ID == "Administrator")
                        result = bo.getGroup(dicLike, dicEqual, pageSize, pageNum);
                    else 
                        result = bo.getSubGroup(dicLike, dicEqual, pageSize, pageNum);
                    break;
                case "getFactory":
                    //厂别
                    result = bo.getGroupFactory(context.Request["groupkey"]);
                    break;
                case "add":
                    //
                    result = bo.addGroup(context);
                    break;
                case "edit":
                    //编辑群组
                    result = bo.editGroup(context);
                    break;
                case "del":
                    //删除群组
                    result = bo.delGroup(context);
                    break;
                case "revert":
                    //还原
                    result = bo.revertGroup(context);
                    break;
                case "getgroupmenu":
                    //获取群组菜单
                    result = bo.getGroupMenu(context.Request["groupkey"], Convert.ToBoolean(context.Request["showall"]));
                    break;
                case "editgroupmenu":
                    //编辑群组菜单
                    result = bo.editGroupMenu(context);
                    break;
                    
            }
        }
        catch (Exception ex)
        {
            var error = new Entities.Status { Success = false, Message = ex.Message };
            result = error.ToJson();

        }
        finally
        {
            context.Response.Write(result);
        }
    }


}
